# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Chris Andrews <christophersimonandrews [at] gmail [dot] com>
# Contributor: FadeMind <fademind@gmail.com>
# Contributor: Serge Victor <arch@random.re>
# Contributor: Krzysztof Wloch <wloszekk [at] gmail [dot] com>
# Contributor: Luke McCarthy <luke@iogopro.co.uk>

pkgname=fasm
pkgver=1.73.31
pkgrel=2
pkgdesc='Fast and efficient self-assembling x86 assembler for DOS, Windows and Linux operating systems'
url='https://flatassembler.net/'
arch=('loong64' 'x86_64')
license=('custom')
depends_x86_64=('lib32-glibc' 'lib32-gcc-libs')
source=(https://flatassembler.net/${pkgname}-${pkgver}.tgz)
sha512sums=('8558ce1ac0eae22d84d8b62e9bd3f6358450329085943eb62e5586b035b351f7eae9ea1288e9527985b63ba631e53c68d2a1fb939b4ac8c39ec687afeca93bcd')
b2sums=('f975ba900cbcbf2c55f57ee37cd6dc2e35573341b93b1a632e0701d6b10776d9642698756d222f50ff6f303a01eba6558a49dac3e39b2b4d3b5ac9d199c051ae')
options=(!strip)

build() {
  cd ${pkgname}

  if [ "${CARCH}" == "x86_64" ]; then
    SRCDIR=Linux/x64
    ./fasm.x64 source/${SRCDIR}/fasm.asm
  fi
  mv source/${SRCDIR}/fasm ./fasm

  # tools
  local s
  for s in listing prepsrc symbols; do
    ./fasm tools/libc/${s}.asm ${s}.o
    gcc -m32 ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -o ${s} ${s}.o
  done
}

package() {
  cd ${pkgname}

  install -Dm 755 fasm -t "${pkgdir}/usr/bin"
  # tools
  local s
  for s in listing prepsrc symbols; do
    install -Dm 755 ${s} "${pkgdir}/usr/bin/fasm-${s}"
  done

  # docs
  install -Dm 644 ${pkgname}.txt whatsnew.txt -t "${pkgdir}/usr/share/doc/${pkgname}"
  install -Dm 644 examples/elfexe/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe"
  install -Dm 644 examples/elfexe/dynamic/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe/dynamic"
  install -Dm 644 examples/elfexe/dynamic/*.inc -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfexe/dynamic"
  install -Dm 644 examples/elfobj/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/elfobj"
  install -Dm 644 examples/libcdemo/*.asm -t "${pkgdir}/usr/share/doc/${pkgname}/examples/libcdemo"
  install -Dm 644 examples/libcdemo/*.inc -t "${pkgdir}/usr/share/doc/${pkgname}/examples/libcdemo"
  install -Dm 644 license.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

# vim: ts=2 sw=2 et:
